package mlz.a_set.c_treeset;


import java.util.Comparator;
import java.util.TreeSet;

//比较器排序
public class TreeSetDemo03 {
    public static void main(String[] args) {
        TreeSet<Person> set = new TreeSet<>(new Comparator<Person>() {
            @Override //o1 和 o2 对象进行对比
            public int compare(Person o1, Person o2) {
                if (o1.getAge() != o2.getAge()){
                    return o2.getAge() - o1.getAge(); //倒序
                }else {
                    return o2.getName().compareTo(o1.getName());
                }
            }
        });
        set.add(new Person("lucy",20));
        set.add(new Person("tom",20));
        set.add(new Person("jack",30));
        set.add(new Person("marry",18));
        set.add(new Person("tom",40));
        set.add(new Person("lucy",20));
        System.out.println(set);

    }
}













